/**
 * 最长公共子序列
 * 2017.4.12 By 杨帆
 */
#include <iostream>
#include <vector>

using namespace std;

/**
 * 求最大增长子序列
 * @param arr 输入
 * @param n 输入长度
 * @param tmp 输出
 * @return 输出长度
 */
vector<int> MaxLengthSubSequence(vector<int> arr)
{
    int n = arr.size();
    vector<int> max(0);
    vector<int> tmp(0);
    for (int j = 1; j < n; ++j)
        if (arr[j] < arr[j - 1] || j == n-1)
            tmp.push_back(j);
    int len = tmp[0];
    for (int i = 1; i < tmp.size(); ++i)
        if (tmp[i] - tmp[i - 1] > len)
        {
            max.clear();
            len = tmp[i] - tmp[i - 1];
            for (int j = 0; j < len; ++j)
                max.push_back(arr[tmp[i - 1] + j]);
        }
    return max;
}

int main()
{
    //Vector方便debug
    int ar[] = {4, 2, 4, 5, 3 ,3 , 3 , 3 , 3 , 3 , 3 ,3 , 3, 6, 5, 9, 7, 12, 45 , 56 , 76 , 99 , 120};
    vector<int> a(ar , ar + 16);

    auto msl = MaxLengthSubSequence(a);

    cout << msl.size() << endl;

    for (int i = 0; i < msl.size(); ++i)
    {
        cout << msl[i] << " ";
    }
    return 0;
}